package 代码记录.指定公司代码练习记录.西安.分值100分;

import java.util.Scanner;

/**
 * @author zx
 * @create 2023-06-28 20:36
 * 暴力很简单
 */
public class 阿里巴巴找黄金宝箱3 {//不看了
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int n = sc.nextInt();
        String[] temp = str.split(",");
        int[] arr = new int[temp.length];
        for(int i = 0;i < arr.length;i++){
            arr[i] = Integer.parseInt(temp[i]);
        }
        boolean flag = true;
        for(int i = 0;i < arr.length;i++){
            for(int j = i + 1;j < arr.length;j++){
                if(arr[i] == arr[j]){
                    if(j - i <= n){
                        System.out.println(i);
                        flag = false;
                        return;
                    }
                }
            }
        }
        if(flag){
            System.out.println(-1);
        }
    }
}
